﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace mozhi.smarterp.Business.Migrations
{
    public partial class _202504121045 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "RequisitionUnitId",
                table: "MozhiPurchaseRequisitionItem",
                newName: "AuxiliaryUnitId");

            migrationBuilder.RenameColumn(
                name: "RequisitionQuantity",
                table: "MozhiPurchaseRequisitionItem",
                newName: "AuxiliaryQuantity");

            migrationBuilder.RenameColumn(
                name: "ReceiptQuantity",
                table: "MozhiPurchaseReceiptItem",
                newName: "ReceivableQuantity");

            migrationBuilder.RenameColumn(
                name: "PurchaseQuantity",
                table: "MozhiPurchaseReceiptItem",
                newName: "AuxiliaryQuantity");

            migrationBuilder.RenameColumn(
                name: "PurchaseUnitId",
                table: "MozhiPurchaseOrderItem",
                newName: "AuxiliaryUnitId");

            migrationBuilder.RenameColumn(
                name: "PurchaseQuantity",
                table: "MozhiPurchaseOrderItem",
                newName: "AuxiliaryQuantity");

            migrationBuilder.AddColumn<Guid>(
                name: "AuxiliaryUnitId",
                table: "MozhiPurchaseReceiptItem",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<decimal>(
                name: "ConversionRate",
                table: "MozhiPurchaseReceiptItem",
                type: "decimal(65,30)",
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<decimal>(
                name: "ConversionRate",
                table: "MozhiPurchaseOrderItem",
                type: "decimal(65,30)",
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.CreateTable(
                name: "MozhiPurchaseProductPrice",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    SupplierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Code = table.Column<string>(type: "varchar(255)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Name = table.Column<string>(type: "varchar(255)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CurrencyId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    IncludeTax = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    ExtraProperties = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MozhiPurchaseProductPrice", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MozhiSaleProductPrice",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CustomerId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Code = table.Column<string>(type: "varchar(255)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Name = table.Column<string>(type: "varchar(255)", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CurrencyId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    IncludeTax = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    ExtraProperties = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MozhiSaleProductPrice", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MozhiPurchaseProductPriceItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    ProductId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    BasicUnitId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    MinQuanity = table.Column<decimal>(type: "decimal(65,30)", nullable: true),
                    MaxQuanity = table.Column<decimal>(type: "decimal(65,30)", nullable: true),
                    Price = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    TaxRateId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    TaxRateValue = table.Column<decimal>(type: "decimal(18,10)", nullable: true),
                    PriceIncludeTax = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    PriceExcludeTax = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    EffectiveDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ExpirationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    PurchaseProductPriceId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MozhiPurchaseProductPriceItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MozhiPurchaseProductPriceItem_MozhiPurchaseProductPrice_Purc~",
                        column: x => x.PurchaseProductPriceId,
                        principalTable: "MozhiPurchaseProductPrice",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MozhiSaleProductPriceItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    ProductId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    BasicUnitId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    MinQuantity = table.Column<decimal>(type: "decimal(65,30)", nullable: true),
                    MaxQuantity = table.Column<decimal>(type: "decimal(65,30)", nullable: true),
                    Price = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    TaxRateId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    TaxRateValue = table.Column<decimal>(type: "decimal(18,10)", nullable: true),
                    PriceIncludeTax = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    PriceExcludeTax = table.Column<decimal>(type: "decimal(18,10)", nullable: false),
                    EffectiveDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ExpirationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    SaleProductPriceId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MozhiSaleProductPriceItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MozhiSaleProductPriceItem_MozhiSaleProductPrice_SaleProductP~",
                        column: x => x.SaleProductPriceId,
                        principalTable: "MozhiSaleProductPrice",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_MozhiPurchaseProductPrice_Code_TenantId",
                table: "MozhiPurchaseProductPrice",
                columns: new[] { "Code", "TenantId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MozhiPurchaseProductPrice_Name_TenantId",
                table: "MozhiPurchaseProductPrice",
                columns: new[] { "Name", "TenantId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MozhiPurchaseProductPriceItem_PurchaseProductPriceId",
                table: "MozhiPurchaseProductPriceItem",
                column: "PurchaseProductPriceId");

            migrationBuilder.CreateIndex(
                name: "IX_MozhiSaleProductPrice_Code_TenantId",
                table: "MozhiSaleProductPrice",
                columns: new[] { "Code", "TenantId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MozhiSaleProductPrice_Name_TenantId",
                table: "MozhiSaleProductPrice",
                columns: new[] { "Name", "TenantId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MozhiSaleProductPriceItem_SaleProductPriceId",
                table: "MozhiSaleProductPriceItem",
                column: "SaleProductPriceId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MozhiPurchaseProductPriceItem");

            migrationBuilder.DropTable(
                name: "MozhiSaleProductPriceItem");

            migrationBuilder.DropTable(
                name: "MozhiPurchaseProductPrice");

            migrationBuilder.DropTable(
                name: "MozhiSaleProductPrice");

            migrationBuilder.DropColumn(
                name: "AuxiliaryUnitId",
                table: "MozhiPurchaseReceiptItem");

            migrationBuilder.DropColumn(
                name: "ConversionRate",
                table: "MozhiPurchaseReceiptItem");

            migrationBuilder.DropColumn(
                name: "ConversionRate",
                table: "MozhiPurchaseOrderItem");

            migrationBuilder.RenameColumn(
                name: "AuxiliaryUnitId",
                table: "MozhiPurchaseRequisitionItem",
                newName: "RequisitionUnitId");

            migrationBuilder.RenameColumn(
                name: "AuxiliaryQuantity",
                table: "MozhiPurchaseRequisitionItem",
                newName: "RequisitionQuantity");

            migrationBuilder.RenameColumn(
                name: "ReceivableQuantity",
                table: "MozhiPurchaseReceiptItem",
                newName: "ReceiptQuantity");

            migrationBuilder.RenameColumn(
                name: "AuxiliaryQuantity",
                table: "MozhiPurchaseReceiptItem",
                newName: "PurchaseQuantity");

            migrationBuilder.RenameColumn(
                name: "AuxiliaryUnitId",
                table: "MozhiPurchaseOrderItem",
                newName: "PurchaseUnitId");

            migrationBuilder.RenameColumn(
                name: "AuxiliaryQuantity",
                table: "MozhiPurchaseOrderItem",
                newName: "PurchaseQuantity");
        }
    }
}
